if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_upbatchrelqty]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_upbatchrelqty]
GO

CREATE    procedure p_upbatchrelqty (
    @btype integer,
    @iqty  decimal(18,4),
    @assqty decimal(18,4),
    @iflag integer,
    @tid integer,
    @actiontype smallint
)
as
  set nocount on
  if (@tid is null) 
    return
 
  if (@actiontype<>0) 
  begin
    update tt_bill set
      brelationqty=brelationqty-@iflag*@actiontype*@iqty,
      brelationassqty=brelationassqty-@iflag*@actiontype*@assqty,
      brelationcount=brelationcount+@actiontype
    where tid=@tid
  end
  else
  begin
    update tt_bill set
      brelationqty=brelationqty-@iflag*@iqty,
      brelationassqty=brelationassqty-@iflag*@assqty
    where tid=@tid
  end
GO

